package io.renren.modules.sys.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.sun.org.apache.bcel.internal.generic.NEW;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.sys.dao.DepotitemDao;
import io.renren.modules.sys.entity.DepotitemEntity;
import io.renren.modules.sys.service.DepotitemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("depotitemService")
public class DepotitemServiceImpl extends ServiceImpl<DepotitemDao, DepotitemEntity> implements DepotitemService {
    @Autowired
    private DepotitemDao depotitemDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<DepotitemEntity> page = this.selectPage(
                new Query<DepotitemEntity>(params).getPage(),
                new EntityWrapper<DepotitemEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public Integer findByType(String type, Integer projectId, Long mId, String monthTime, Boolean isPrev) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("type",type);
        map.put("projectId",projectId);
        map.put("monthTime",monthTime+"-01 00:00:00");
        map.put("endMonthTime",monthTime+"-31 59:59:59");
        map.put("mId",mId);
        map.put("isPrev",isPrev);
        return depotitemDao.findByType(map);
    }

    @Override
    public Double findPriceByType(String type, Integer projectId, Long mId, String monthTime, Boolean isPrev) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("type",type);
        map.put("projectId",projectId);
        map.put("monthTime",monthTime+"-01 00:00:00");
        map.put("endMonthTime",monthTime+"-31 59:59:59");
        map.put("mId",mId);
        map.put("isPrev",isPrev);
        return depotitemDao.findPriceByType(map);
    }

    @Override
    public Double buyOrSale(String type, String subType, Long mId, String monthTime, String sumType) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("type",type);
        map.put("sumType",sumType);
        map.put("subType",subType);
        map.put("monthTime",monthTime+"-01 00:00:00");
        map.put("endMonthTime",monthTime+"-31 59:59:59");
        map.put("mId",mId);
        return depotitemDao.buyOrSale(map);
    }

    @Override
    public Integer findGiftByType(String subType, Integer projectId, Long mId, String type) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("type",type);
        map.put("projectId",projectId);
        map.put("subType",subType);
        map.put("mId",mId);
        return depotitemDao.findGiftByType(map);
    }

    @Override
    public Integer findByTypeAndMaterialId(String type, Long mId) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("type",type);
        map.put("mId",mId);
        return depotitemDao.findByTypeAndMaterialId(map);
    }

    @Override
    public List<HashMap> findDetailByTypeAndMaterialId(String mid,Integer start,Integer end) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("mId",mid);
        map.put("start",start);
        map.put("end",end);
        return depotitemDao.findDetailByTypeAndMaterialId(map);
    }

}
